var express = require('express');
var router = express.Router();
//引入不可少

router.get('/', function(req, res, next) {
	// res.send("lunbo");
	var type = req.query.type;
	var index = req.query.index;
	var sql = 'select title , url from lunbo where type='+type+' and idx='+index;
	myQuery(req, res, next , sql);
});

function myQuery(req, res, next , sql){
	var mysql = require('mysql');
	var connection = mysql.createConnection({
	    host: '106.14.254.124',          //主机 
	    user: 'wangruiyu',               //MySQL认证用户名 
	    password: 'Wangruiyu1990',       //MySQL认证用户密码 
	    database: 'wangruiyu', 
	    port: '3306'                     //端口号 
	});
	connection.connect();
	connection.query(sql, function(err, results) {
	  if (err) throw err;
	  res.send(results);
	});
	connection.end();
}

//不可少
module.exports = router;
